package com.lagou.goods.controller;


import com.lagou.common.pojo.Products;
import com.lagou.goods.service.ProductsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.kafka.core.KafkaTemplate;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/products")
public class ProductsController {

    @Autowired
    private ProductsService productsService;
    @Autowired
    private KafkaTemplate<String,Integer> template;

    @PostMapping("/insert")
    public String insert(Products products) {

        int i = productsService.insert(products);
        System.out.println("id = " + products.getId());

        // 发送
        template.send("product",products.getId());

        return i == 0 ? "添加失败" : "添加成功";
    }

}
